package com.xjtu.platform.security.register;
import com.xjtu.platform.common.Result;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Random;


@RestController
@RequestMapping("/security/Register")
public class RegisterAPI {

    @Resource
    private RegisterService registerService;

    @PostMapping("")
    public Result Register(@RequestBody RegisterDto registerDto){
        String role = registerService.getRole(registerDto);
        if(role == null){
            return Result.fail(Result.ERR_CODE_BUSINESS,"工号不存在!!");
        }
        boolean result = registerService.insertUser(registerDto,role);
        if(result){
            return Result.success("注册成功，请完善邮箱");
        }else {
            return Result.fail(Result.ERR_CODE_SYS,"系统维护中......");
        }
    }


}
